package mapWorking;

import java.util.HashMap;
import java.util.Map;
/**
Consider the following code:

public class User {
   private String name;
   // setters and getters
}

Map<User, Integer> points = new HashMap<>();

User user = new User();
user.setName('Vova');

points.put(user, 10);

user = new User();
user.setName('Vova');

Integer p = points.get(user);

System.out.println('Vova has ' + p + ' points.'):

Question: Is this ok? If not what would you change to print Vova's points?

 */
public class User {
	private String name;

	public static void main(String args[]) {

		Map<User, Integer> points = new HashMap<User, Integer>();

		User user = new User();
		user.setName("Vova");
		points.put(user, 10);

		user = new User();
		user.setName("Vova");

		Integer p = points.get(user);
		System.out.println("Vova has " + p + " points.");

	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public boolean equals(Object u) {
		if (!(u instanceof User)) {
			return false;
		}
		User user = (User) u;
		if (user.getName() == name) {
			return true;

		} else {

			return false;
		}

	}

	@Override
	public int hashCode() {
		int hash = 3;
		hash = 53 * hash + (this.name != null ? this.name.hashCode() : 0);
		hash = 53 * hash;
		return hash;
	}

}
